package com.osmap.openstreetmap.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.osmap.openstreetmap.R;
import com.osmap.openstreetmap.bean.ShareBeans;

public class HomeAdapter extends BaseAdapter {

	public List<ShareBeans> list;

	public Context mContext;

	public LayoutInflater mInflater;

	public HomeAdapter(List<ShareBeans> list, Context mContext) {
		super();
		this.list = list;
		this.mContext = mContext;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_map, null);
			holder.title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.time = (TextView) convertView
					.findViewById(R.id.tv_publishtime);
			holder.collectCount = (TextView) convertView
					.findViewById(R.id.tv_collect_time);
			holder.desc = (TextView) convertView.findViewById(R.id.tv_desc);
			holder.mapImg = (ImageView) convertView
					.findViewById(R.id.iv_map_min);
			holder.headImg = (ImageView) convertView
					.findViewById(R.id.iv_headimg);
			holder.mapCount = (TextView) convertView
					.findViewById(R.id.tv_footmark_miles);
			convertView.setTag(holder);
		}
		ShareBeans beans = list.get(position);
		holder = (ViewHolder) convertView.getTag();
		holder.title.setText(beans.nickname);
		holder.time.setText(beans.publishTime + "分钟前发布");
		holder.mapCount.setText(beans.miles + "公里");
		holder.collectCount.setText(beans.collectionCount + "次收藏");
		holder.desc.setText(beans.desc);
		return convertView;
	}

	class ViewHolder {
		public TextView title;
		public TextView time;
		public TextView desc;
		public TextView collectCount;
		public TextView mapCount;
		public TextView milesCount;
		public ImageView headImg;
		public ImageView mapImg;

	}

}
